package com.tzbank.common.service.impl;

import com.tzbank.common.kafka.interfaces.GreetingsChannel;
import com.tzbank.common.service.TestService;
import com.tzbank.kafka.KafkaMethodReq;
import com.tzbank.kafka.KafkaParamsReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.util.MimeTypeUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class TestServiceImpl implements TestService{

    @Autowired
    GreetingsChannel greetingsChannel;

    @Override
    public void testKafka() {
        KafkaMethodReq kafkaMethodReq = new KafkaMethodReq();
        kafkaMethodReq.setClassName(TestServiceImpl.class);
        kafkaMethodReq.setMethod("test");
        List<KafkaParamsReq> kafkaParamsReqList = new ArrayList<KafkaParamsReq>();
        KafkaParamsReq kafkaParamsReq = new KafkaParamsReq();
        kafkaParamsReq.setTypeClass(String.class);
        kafkaParamsReq.setParamValue("哈哈哈哈哈");
        kafkaParamsReqList.add(kafkaParamsReq);
        kafkaMethodReq.setParamsReqList(kafkaParamsReqList);
        MessageChannel messageChannel = greetingsChannel.outboundGreetings();
        messageChannel.send(MessageBuilder.withPayload(kafkaMethodReq).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build());
    }

    @Override
    public void test(String aa) {
        System.out.print("param:"+aa);
    }
}
